package project.base.common.filter

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.stereotype.Component
import java.io.IOException
import javax.servlet.*
import javax.servlet.annotation.WebFilter
import javax.servlet.http.HttpServletRequest

/**
 * xxs攻击 拦截器
 * @author: 三味
 * @update: 2022/3/3 15:57
 */
@WebFilter
@Component
@Configuration
open class XssFilter : Filter {

    @Bean
    open fun authenticationXssFilterBean(): XssFilter? {
        return XssFilter()
    }

    @Throws(ServletException::class)
    override fun init(filterConfig: FilterConfig?) {
    }

    @Throws(IOException::class, ServletException::class)
    override fun doFilter(request: ServletRequest?, response: ServletResponse?, chain: FilterChain) {
        val req = request as HttpServletRequest?
        val xssRequestWrapper = XssAndSqlHttpServletRequestWrapper(req)
        chain.doFilter(xssRequestWrapper, response)
    }

    override fun destroy() {}

}
